﻿using System;
using System.Data;
using System.Collections.Generic;
using SERP.DAO;
namespace SERP.Controllers{
public class UsersControllerBase : Controller{
	public UsersControllerBase()
		: base()
	{
	}
	private static UsersDAO _Service; 
	public static UsersDAO Service{
		get{
			if(_Service==null)
				_Service = new UsersDAO();
			return _Service;
		}
		set{
			_Service = value;
		}
	}
    //Copy data from data row in grid to object
    public UsersEntity MapDataRowToObject(DataRow row){
		UsersEntity o = new UsersEntity();
		 o.UserName=Convert.ToString(row["UserName"]);
		 o.Password=Convert.ToString(row["Password"]);
		 o.DisplayName=Convert.ToString(row["DisplayName"]);
		 if(!row.IsNull("BirthDay"))
			o.BirthDay=ConvertDateTime(row["BirthDay"]);
		 o.Email=Convert.ToString(row["Email"]);
		 if(!row.IsNull("Gender"))
			o.Gender=ConvertByte(row["Gender"]);
		 o.Address=Convert.ToString(row["Address"]);
		 o.Phone=Convert.ToString(row["Phone"]);
		 if(!row.IsNull("IsActived"))
			o.IsActived=ConvertBool(row["IsActived"]);
		 if(!row.IsNull("UserType"))
			o.UserType=ConvertByte(row["UserType"]);
		 if(!row.IsNull("UserId"))
		    o.UserId=(Int32)(row["UserId"]);
		 return o;
    }
	//Copy data from object to data row in grid    
    public void MapObjectToDataRow(UsersEntity o,DataRow row){
		row["UserName"]=o.UserName;
		row["Password"]=o.Password;
		row["DisplayName"]=o.DisplayName;
		row["BirthDay"]=o.BirthDay;
		row["Email"]=o.Email;
		row["Gender"]=o.Gender;
		row["Address"]=o.Address;
		row["Phone"]=o.Phone;
		row["IsActived"]=o.IsActived;
		row["UserType"]=o.UserType;
		row["UserId"]=o.UserId;
    }
}
}
